package com.ktkq.util;

import java.util.ArrayList;
import java.util.List;

public class PageFinder<T> {
 

	private int pageSize = 5;  //每页记录数
	private List<T> dataList = new ArrayList<T>();   //当前页存放的数据
	private int rowCount;  //总记录数
	private int pageCount;   //页数
	private int pageNo = 1;  //跳转页数
	private boolean hasPrevious = false;  //是否有上一页
	private boolean hasNext = false;   //是否有下一页

	
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public List<T> getDataList() {
		return dataList;
	}
	public void setDataList(List<T> dataList) {
		this.dataList = dataList;
	}
	public int getRowCount() {
		return rowCount;
	}
	public void setRowCount(int rowCount) {
		this.rowCount = rowCount;
	}
	public int getPageCount() {
		if (rowCount % pageSize == 0){
			return rowCount / pageSize;
		}else{
			return rowCount / pageSize + 1;
		}
	}
	public void setPageCount(int pageCount) {
		this.pageCount = pageCount;
	}
	public int getPageNo() {
		return pageNo;
	}
	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}
	public boolean isHasPrevious() {
		return hasPrevious;
	}
	public void setHasPrevious(boolean hasPrevious) {
		this.hasPrevious = hasPrevious;
	}
	public boolean isHasNext() {
		return hasNext;
	}
	public void setHasNext(boolean hasNext) {
		this.hasNext = hasNext;
	}
	/**
	 * 获取跳转页第一条数据在数据集的位置
	 */
	public int getStartOfPage() {
		return (pageNo - 1) * pageSize;
	}
	//结束纪录数
		public int getEndRow(){
			return pageNo*pageSize;
		}
	/**
	 * 获取总页数
	 */
	public final int getTotalPageCount() {
		if (rowCount % pageSize == 0){
			return rowCount / pageSize;
		}else{
			return rowCount / pageSize + 1;
		}
	}
	/**
	 * 刷新当前分页对象数据
	 */
	public void refresh() {
		if (pageCount <= 1) {
			hasPrevious = false;
			hasNext = false;
		} else if (pageNo == 1) {
			hasPrevious = false;
			hasNext = true;
		} else if (pageNo == pageCount) {
			hasPrevious = true;
			hasNext = false;
		} else {
			hasPrevious = true;
			hasNext = true;
		}
	}	
	
}
